home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / include / stringedit.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-24  |  2.5 KB  |  104 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1987, 1988, 1989 Stanford University
  5.    Copyright (c) 1989, Tera Computer Company
  6.  **/
  7.  
  8.   /**
  9.      stolen from the InterViews 2.5 source files (text directory, which 
  10.      is unsupported in 2.6.  
  11.    **/
  12.  
  13. /*
  14.  * StringEdit - basic interactive editor for character strings
  15.  */
  16.  
  17. #ifndef stringedit_h
  18. #define stringedit_h
  19.  
  20. #include <InterViews/interactor.h>
  21.  
  22. class Event;
  23. class Painter;
  24. class Sensor;
  25.  
  26. static const int SEClipSize = 1024;        // class-static clipboard
  27. static const int SEBufferSize = SEClipSize;    // per-instance work buffer
  28.  
  29. class StringEdit : public Interactor {
  30. public:
  31.     StringEdit(const char* sample, int border = 3);
  32.     StringEdit(const char* name, const char* sample, int border = 3);
  33.     StringEdit(const char* sample, Painter*, int border = 3);
  34.     ~StringEdit();
  35.  
  36.     void Extra(int);
  37.     void Flash(int);
  38.     void SetString(const char*, boolean select = true);
  39.     char* GetString();
  40.     virtual void Reshape(Shape&);
  41.     virtual void Handle(Event&);
  42. protected:
  43.     static char clip[SEClipSize];
  44.     static int cliplength;
  45.  
  46.     const char* sample;
  47.     const char* old;                // sample or last SetString
  48.     char* buffer;                // working storage
  49.  
  50.     Painter* highlight;
  51.     Sensor* edit;
  52.     Sensor* select;
  53.  
  54.     int size;                    // max length of buffer
  55.     int length;                    // current length of buffer
  56.     int prev, next;                // selection pointers
  57.     int hitprev, hitnext;            // initial selection
  58.     int extra;                    // characters to grow by
  59.     int border;                    // pixels around edge
  60.  
  61.     boolean selecting;                // dragging across text
  62.     boolean caret;                // caret is visible
  63.  
  64.     int lasttime;                // last up event
  65.     int lastx, lasty;
  66.  
  67.     void Init(const char* sample, int border);
  68.     virtual void Redraw(Coord, Coord, Coord, Coord);
  69.     virtual void Reconfig();
  70.  
  71.     boolean DoubleClick(Event&);
  72.     boolean EmptySelection() { return next == prev+1; }
  73.     boolean AtBegin() { return prev <= -1; }
  74.     boolean AtEnd() { return next >= length; }
  75.  
  76.     void ShowSelection();
  77.     void HideSelection();
  78.     void ShowCaret();
  79.     void HideCaret();
  80.     void DrawCaret(int);
  81.  
  82.     void Restart();
  83.     void FixSize();
  84.     void DoChar(char c);
  85.     void Refresh(int from, int to, Painter*);
  86.     int Hit(Coord);
  87.  
  88.     void AddChar(char c);
  89.     void DeleteChar(int);
  90.  
  91.     void Clear();
  92.     void Cut();
  93.     void Copy();
  94.     void Paste();
  95.  
  96.     void StartSelection(Coord);
  97.     void ExtendSelection(Coord);
  98.     void Select();
  99.     void SelectWord();
  100.     void Unselect();
  101. };
  102.  
  103. #endif
  104.